﻿using System;
using AutoMapper;
using K9Nano.Application.MultiTenancy;
using K9Nano.Application.Organization.Dto;
using K9Nano.MultiTenancy;
using K9Nano.Organization;

namespace K9Nano.Application
{
    public class MapperProfile: Profile
    {
        public MapperProfile()
        {
            #region Tenant

            // Tenant
            CreateMap<TenantCreateInput, Tenant>();
            CreateMap<Tenant, TenantDto>();

            #endregion

            #region OU

            CreateMap<OrganizationUnit, OrganizationUnitDto>();
            CreateMap<OrganizationUnitCreateInput, OrganizationUnit>()
                .ForMember(x => x.ParentId,
                    m => m.MapFrom(a => string.IsNullOrWhiteSpace(a.ParentId) ? (Guid?)null : Guid.Parse(a.ParentId)));
            CreateMap<OrganizationUnitUpdateInput, OrganizationUnit>()
                .ForMember(x => x.ParentId,
                    m => m.MapFrom(a => string.IsNullOrWhiteSpace(a.ParentId) ? (Guid?)null : Guid.Parse(a.ParentId)));

            #endregion

        }
    }
}